from socket import *
from multiprocessing import Process


def fun(clientSocket):
    recvData = clientSocket.recv(1024)
    print("recvdata = ", recvData)
    responseHeaderLines = "HTTP/1.1 200 OK\r\n"
    responseHeaderLines += "\r\n"
    responseBody = "hello world"

    response = responseHeaderLines + responseBody
    clientSocket.send(bytes(response, "utf-8"))
    clientSocket.close()


if __name__ == "__main__":
    serSocket = socket(AF_INET, SOCK_STREAM)
    serSocket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
    serSocket.bind(("", 7000))
    serSocket.listen(12)
    while True:
        clientSocket, clientAddr = serSocket.accept()
        print(str(clientAddr), "连上了")
        p1 = Process(target=fun, args=(clientSocket,))
        p1.start()
        clientSocket.close()
